<template>
  <div class="xq-form-wrapper">
    <a-spin :spinning="spinning" class="xq-form-content">
      <XqTable
        :customize="FormJson['config']['table']['customize']"
        :scroll="{ x: columns.length * 150 }"
        :pagination="false"
        :dataSource="tableData"
        :columns="columns"
        :row-selection="
          FormJson['config']['table']['extend']['batch']
            ? {
                selectedRowKeys: selectedRowKeys,
                onChange: onSelectChange
              }
            : null
        "
        class="xq-form-content-table"
        @change="onTableChange"
      >
        <!-- 主要内容，表格，自定义 header -->
        <template v-for="(col, index) in columns" v-slot:[`xq_${col.dataIndex}`]>
          <span :key="index">
            {{ col.customTitle }}
          </span>
        </template>
        <!-- 主要内容，表格，自定义 td -->
        <!-- eslint-disable-next-line prettier/prettier -->
        <template v-for="(col, index) in columns" v-slot:[col.dataIndex]="text, record">
          <span v-if="col.dataIndex === 'gmtCreate'" :key="index">
            {{ moment(text).format("YYYY-MM-DD") }}
          </span>
          <span v-else-if="col.dataIndex === 'cityName'" :key="index">
            {{ text ? text.split(",")[1] : "" }}
          </span>
          <span v-else-if="col.dataIndex === 'tableAction'" :key="index">
            <a @click="onEvaluate(record)">面试评价</a>
            <a-divider type="vertical" />
            <a-popconfirm title="确认为不合适吗？" ok-text="确认" cancel-text="取消" @confirm="onClose(record.id, record.isBroker)">
              <a>不合适</a>
            </a-popconfirm>
          </span>
          <XqTableCell v-else :key="index" :record="record" :field="FormJson['fields'][col.dataIndex]" :dynamicData="dynamicData" />
        </template>
      </XqTable>
      <div class="xq-form-content-pagination">
        <div class="xq-form-content-pagination-total">共 {{ total }} 条</div>
        <a-pagination
          v-model="pageNo"
          :page-size="pageSize"
          :total="total"
          :show-size-changer="true"
          :show-quick-jumper="true"
          :page-size-options="['10', '20', '50', '100']"
          @change="onPageChange"
          @showSizeChange="onPageSizeChange"
        />
      </div>
    </a-spin>
    <evaluate
      :visible.sync="visible"
      :evaluateId="evaluateId"
      :recruitInfoId="recruitInfoId"
      :companyUnitsId="companyUnitsId"
      @upDate="upDate"
    />
  </div>
</template>

<script>
import FormJson from "./FormJson";
import XqCurdMixin from "xqjr-plugin-form/mixins/XqCurdMixin";
// import { getFindPostByQuery, putRecruitInfos } from "./api";
import evaluate from "../../../../people/component/evaluate";
import moment from "moment";

const curdMixin = new XqCurdMixin({
  FormJson,
  tableConfigKey: "table"
});

export default {
  components: {
    evaluate
  },
  mixins: [curdMixin],
  data() {
    return {
      visible: false,
      spinning: false,
      tableData: [{}],
      total: 0,
      pageNo: 1,
      pageSize: 20,
      evaluateId: "",
      recruitInfoId: "",
      companyUnitsId: ""
    };
  },
  created() {
    // this.onGetFindPostByQuery();
  },
  methods: {
    moment,
    async onGetFindPostByQuery() {
      try {
        this.spinning = true;
        // const { data } = await getFindPostByQuery({
        //   "orders[0].property": "gmtCreate",
        //   "orders[0].desc": true,
        //   isBroker: 1,
        //   postName: this.postName,
        //   cityName: this.socCityName,
        //   pageNo: this.pageNo,
        //   pageSize: this.pageSize
        // });
        // this.tableData = data.entities;
        // this.total = data.entityCount;
        setTimeout(() => (this.spinning = false), 500);
      } catch (err) {
        console.log("error log --> ", err);
        setTimeout(() => (this.spinning = false), 500);
      }
    },
    onPageChange(page) {
      this.pageNo = page;
      this.onGetFindPostByQuery();
    },
    onPageSizeChange(current, pageSize) {
      this.pageNo = 1;
      this.pageSize = pageSize;
      this.onGetFindPostByQuery();
    },
    onEvaluate(e) {
      this.evaluateId = "";
      this.recruitInfoId = "";
      this.companyUnitsId = "";
      this.visible = true;
    },
    upDate(e) {
      this.evaluateId = "";
      this.recruitInfoId = "";
      this.companyUnitsId = "";
      this.visible = false;
    },
    async onClose(id, isBroker) {
      try {
        // await putRecruitInfos({
        //   id,
        //   isBroker: isBroker === 1 ? 2 : 1
        // });
        // this.onGetFindPostByQuery();
      } catch (err) {
        console.log("error log --> ", err);
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
